//
//  HYOnlineCell.m
//  HaiYue
//
//  Created by skyline on 2017/12/19.
//  Copyright © 2017年 skyline. All rights reserved.
//

#import "HYOnlineCell.h"
#import "HYOnlineBarCell.h"
NSString *const CCNoticeNameOnlineCellClick = @"CCNoticeNameOnlineCellClick";

@interface HYOnlineCell()
@property (nonatomic, strong) HYImageView *IMG;
@property (nonatomic, strong) HYLabel *titleLBL;
@property (nonatomic, strong) HYLabel *memoryLBL;
@property (nonatomic, strong) HYLabel *styleLBL;
@property (nonatomic, strong) HYLabel *descriptionLBL;
@property (nonatomic, strong) HYButton *installBtn;
@property (nonatomic, strong) HYView *line;
@end
@implementation HYOnlineCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.line.hidden = NO;
    }
    return self;
}
- (HYView *)line
{
    if (!_line)
    {
        _line = [[HYView alloc] initWithColor:CELL_LINE_COLOR];
        [self addSubview:_line];
        [_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _line;
}
- (HYImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[HYImageView alloc]initWithImage:[UIImage imageNamed:@"1"] cornerRadius:CornerRadius];
        [self addSubview:_IMG];
        [_IMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(HYOnlineCellIMG_Width, HYOnlineCellIMG_Width));
        }];
    }
    return _IMG;
}

- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[HYLabel alloc]initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:DefaultFont]];
        [self addSubview:_titleLBL];
        [_titleLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.IMG.mas_right).with.offset(5);
            make.top.equalTo(self.IMG).with.offset(-HYOnlineCellLBL_Gap);
        }];
    }
    return _titleLBL;
}

- (HYLabel *)memoryLBL
{
    if (!_memoryLBL)
    {
        _memoryLBL = [[HYLabel alloc]initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:13]];
        [self addSubview:_memoryLBL];
        [_memoryLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.IMG.mas_right).with.offset(5);
            make.centerY.equalTo(self);
        }];
    }
    return _memoryLBL;
}

- (HYLabel *)descriptionLBL
{
    if (!_descriptionLBL)
    {
        _descriptionLBL = [[HYLabel alloc]initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:13]];
        [self addSubview:_descriptionLBL];
        [_descriptionLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.IMG.mas_right).with.offset(5);
            make.bottom.equalTo(self.IMG.mas_bottom).with.offset(HYOnlineCellLBL_Gap);
        }];
    }
    return _descriptionLBL;
}

- (HYButton *)installBtn
{
    if (!_installBtn)
    {
        _installBtn = [[HYButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40) title:@"安装" titleColor:THEME_COLOR];
        _installBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _installBtn.type = CCShapeLayerTypeCycle;
        [_installBtn addTarget:self action:@selector(actionForInstallBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_installBtn];
        [_installBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).with.offset(- GAP);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(self.installBtn.bounds.size);
        }];
    }
    return _installBtn;
}
- (void)setModel:(HYOnlineGameModel *)model
{
    if (_model != model)
    {
        _model = model;
        self.IMG.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_model.icon]]];
        self.titleLBL.text = _model.gamename;
        self.memoryLBL.text = _model.size;
        self.descriptionLBL.text = _model.simpledesc;
    }
}
//
//- (void)setType:(HYOnlineCellType)type
//{
//    if (_type != type)
//    {
//        _type = type;
//        if (_type == HYOnlineCellDefaultType)
//        {
//            self.IMG.hidden = NO;
//            self.installBtn.hidden = NO;
//        }
//        else if(_type == HYOnlineCellBarType)
//        {
//            _IMG.hidden = _installBtn.hidden = _memoryLBL.hidden = _styleLBL.hidden = _descriptionLBL.hidden = YES;
//        }
//        else
//        {
//            self.IMG.hidden = NO;
//            [self.installBtn setTitle:@"开始" forState:UIControlStateNormal];
//        }
//    }
//}


- (void)actionForInstallBtn
{
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    [CCNotice post:CCNoticeNameOnlineCellClick obj:nil info:@{@"gameid":self.model.gameid}];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
}

@end
